<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Create error browse page
 * get error.tpl.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2015
 * @author     Norbert Gebert
 * @license    GPL3
 */
db::getInstance()->orderBy('error_date', 'ASC');
$result = db::getInstance()->get('error');

if (db::getInstance()->count <= 0)
{
	message::setErrorRow(_('No Errorentry in Database.'), true);
}
else
{
	$refPage->assign('page_title', _('System error list'));
	$refPage->assign('summary', _('This table gives a overview of the systemerrors'));

	$refPage->assign('errorId', _('ID'));
	$refPage->assign('errorText', _('Name'));
	$refPage->assign('errorDate', _('Date'));
	$refPage->assign('errorDone', _('Done'));

	$refPage->assign('Form_Start',
		'<form class="niceform fieldset" action="' .
		'index2.php?page=' . $page . '&sub=' . $subpage .
		'" method="post"><fieldset>');
	$refPage->assign('Form_End', '</fieldset></form>');
	$data = array();

	foreach ($result as $row)
	{ // Build 5 columns
		$done = '<a href="index2.php?page=' . $page . '&sub=' . $subpage . '&id=' .
			$row['error_id'] . '&active=1">';

		if ($row['error_done'] === 0)
			$done .= '<img src="template/images/page.article/notactive.gif"></a>';
		else
			$done .= '<img src="template/images/page.article/isactive.gif"></a>';

		$errorTextx = '<a href="index2.php?page=' . $page . '&sub=' . $subpage . '&id=' .
			$row['error_id'] . '&func=edit">';
		$errorTextx .= substr($row['error_text'], 0, strpos($row['error_text'], '<br>')) . '</a>';

		$data[] = array('errorSetx' => '<input type="checkbox" name="marker[]" value="' .
		 $row['error_id'] . '" />',
		 'errorTextx' => $errorTextx,
		 'errorDatex' => $row['error_date'],
		 'errorDonex' => $done);
	}

	$refPage->assign('data', $data);

	$refPage->assign('btnDelete',
		'<input type="submit" name="submit" id="delete" value="' .
		_('Delete') . '" />');

	$refPage->assign('tableHelp', help('error', $page, TRUE));
	$refPage->addtpl('content', '/' . $page . '/' . $subpage . '.tpl.php');
}
?>